package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.domain.ScenicTicket;
import cn.wolfcode.trip.base.query.TicketObject;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.ITicketService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 后台管理所有的景点售票情况
 */
@Controller
@RequestMapping("/ticket")
public class ScenicTicketController {

    @Autowired
    private ITicketService service;
    @Autowired
    private IRegionService regionService;

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    //景点售票的保存或新增
    public Object saveOrUpdate(ScenicTicket s) {
        JSONResult jsonResult = new JSONResult();
        try {
            if (s.getId() == null) {
                service.save(s);
            } else {
                service.update(s);
            }
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark(e.getMessage());
        }
        return new JSONResult();
    }

    @RequestMapping("/list")
    //晋点售票
    public String list(Model model, @ModelAttribute("qo") TicketObject qo) {
        PageInfo pageInfo = service.query(qo);
        model.addAttribute("result", pageInfo);
        //回显所有的地区,进行高级查询
        model.addAttribute("regions", regionService.list());
        return "/ticket/list";
    }


}
